package fr.utbm.gi.vi51.project.agent;

import javax.vecmath.Vector2d;

import org.janusproject.kernel.status.Status;

import fr.utbm.gi.vi51.framework.environment.Animat;
import fr.utbm.gi.vi51.project.agent.body.ProjectileBody;
import fr.utbm.gi.vi51.project.agent.body.UnitBody;
import fr.utbm.gi.vi51.project.behavior.BehaviourOutput;
import fr.utbm.gi.vi51.project.behavior.SeekBehaviour;
import fr.utbm.gi.vi51.project.behavior.steering.SteeringSeekBehaviour;

public abstract class Projectile extends Animat<ProjectileBody> {

	private static final long serialVersionUID = -2796624809511103668L;

	protected final SeekBehaviour<?> seekBehaviour;
	private UnitBody targetBody;

	public Projectile(UnitBody targetBody) {
		this.seekBehaviour = new SteeringSeekBehaviour();
		this.targetBody = targetBody;
	}

	@Override
	public Status live() {
		if (new Vector2d(this.targetBody.getX() - getPosition().getX(), this.targetBody.getY() - getPosition().getY())
				.length() < 8) {
			explode();
		} else {
			BehaviourOutput behaviour = this.seekBehaviour.runSeek(getPosition(), getDirection(),
					getCurrentLinearSpeed(), getMaxLinearSpeed(), this.targetBody.getPosition(), null);
			influenceKinematic(behaviour.getLinear(), behaviour.getAngular());
		}
		return null;
	}

	public abstract void explode();

}
